package com.happy.people.cofig;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
* @Description: 登录拦截器
* @Param:
* @return:
* @Author: Mr.Yan
* @Date: 2018/12/11
*/

@Configuration
public class WebConfig extends WebMvcConfigurationSupport {


    @Bean
    public SecurityInterceptor getSecurityInterceptor() {
        return new SecurityInterceptor();
    }
    /**
     * 加载静态资源
     * @param registry
     */
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/")
                .addResourceLocations("classpath:/static/")
                .addResourceLocations("classpath:/static/**")
                .addResourceLocations("classpath:/templates/")
                .addResourceLocations("classpath:/templates/**");
        super.addResourceHandlers(registry);
    }
    /**
     * 对地址进行拦截
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration addInterceptor = registry.addInterceptor(getSecurityInterceptor());
        // 拦截配置
        addInterceptor.addPathPatterns("/**");
        addInterceptor.excludePathPatterns("/common/**","/jquery-3.4.1/**","/jquery-qrcode-master/**");
        super.addInterceptors(registry);
    }
}
